import { sys, native } from "cc";
import { IOS, JSB, WECHAT_MINI_PROGRAM } from "cc/env";

export default class JsbUtils {
    /**
     * 调用手机震动功能
     * desc
     * @date 2024-04-19
     * @param { any } data
     * @returns { void }
     */
    public static callVibration(data: any): void {
        if (JSB) {
            console.log("进入原生平台调用震动");
            if (sys.os == sys.OS.IOS) {
                console.log("ios震动功能");
                // @ts-ignore
                // native.bridge.sendToNative('callVibration', data.toString());
                // jsb.reflection.callStaticMethod('JsBridge', 'sayMe');
                native.reflection.callStaticMethod('JSB', 'callVibration:', data);
            } else if (sys.os == "Android") {
                console.log("android震动功能");
                try {
                    // jsb.reflection.callStaticMethod("org.cocos2dx.javascript/AppActivity", "callVibration", "()V");
                } catch (e) {
                    console.log("error is ", e);
                }
            }
        }

        // @ts-ignore
        if (WECHAT_MINI_PROGRAM && wx) {
            // @ts-ignore
            wx.vibrateShort({
                type: 'light',
                success: () => {

                }
            });
        }
    }

}
export const jsbUtils = new JsbUtils();
